#include <cstring>
#include <GL/freeglut.h>

#include "GameManager.h"
#include "EnemyEntities.h"

GameManager::GameManager():
m_isActive(false),
m_gameBoard(NULL),
m_player(NULL)
{
	
}

GameManager::~GameManager()
{
	if (NULL != m_gameBoard)
	{
		delete m_gameBoard;
	}

	if (NULL != m_player)
	{
		delete m_player;
	}
}

void GameManager::Tick()
{
}

bool GameManager::IsActive()
{
	return m_isActive;
}

bool GameManager::Initialize(int argc, char **argv)
{
	return true;
}

bool GameManager::StartNewGame(WorldManager * worldMgr)
{
	if (NULL != m_gameBoard)
	{
		delete m_gameBoard;
		m_gameBoard = NULL;
	}

	if (NULL != m_player)
	{
		delete m_player;
		m_player = NULL;
	}

	m_gameBoard = new GameBoard(40, 30, 800, 600);
	m_gameBoard->GenerateBoard();
	m_player = new PlayerEntity();
	m_player->SetPosition(5, 5);
	worldMgr->AddEntity(m_player);
	SnakeEntity* e = new SnakeEntity();
	e->SetPosition(10, 10);
	worldMgr->AddEntity(e);
	m_isActive = true;

	worldMgr->SetGameBoard(m_gameBoard);
	return true;
}

void GameManager::ProcessMouse(int x, int y)
{

}

void GameManager::ProcessMouseClick(int button, int state, int x, int y)
{

}

void GameManager::KeyboardInput(unsigned char c, int x, int y)
{
	m_player->KeyboardInput(c,x,y);
}

void GameManager::ProcessSpecialInput(int key, int x, int y)
{
	m_player->ProcessSpecialInput(key, x, y);
}

bool GameManager::EndGame(bool success)
{
	exit(0);
}